﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.SessionState;
using System.Web.Profile;
using System.Web;

namespace SysComm
{
    public class SysUtil
    {
        public static string m_strVersion = "1.0.0.1";//系统版本号

        public static string m_strServerPath = "";

        public static string m_strDBServerIP = "127.0.0.1";
        public static string m_strDBUserID = "sa";
        public static string m_strDBPassWord = "rootbeer";
        public static string m_strDBDataBase = "IP_App";

        public static string m_functiong_user_manage = "IPMS_USER_MANAGE";
        public static string m_functiong_usergroup_manage = "IPMS_USERGROUP_MANAGE";
        public static string m_functiong_login = "IPMS_LOGIN";
        public static string m_functiong_project = "IPMS_PROJECT";
        public static string m_functiong_projectgroup = "IPMS_PROJECTGROUP";
        public static string m_functiong_product = "IPMS_PRODUCT";
        public static string m_functiong_projectclass = "IPMS_PROJECTCLASS";
        public static string m_functiong_agent = "IPMS_AGENT";
        public static string m_functiong_client = "IPMS_CLIENT";
        public static string m_functiong_country = "IPMS_COUNTRY";
        public static string m_functiong_procedure = "IPMS_PROCEDURE";
        public static string m_functiong_document = "IPMS_DOCUMENT";

        public static string[] m_sysfunctions ={ 
                m_functiong_user_manage, 
                m_functiong_usergroup_manage, 
                m_functiong_login, 
                m_functiong_project,
                m_functiong_projectgroup,
                m_functiong_product,
                m_functiong_projectclass,
                m_functiong_agent,
                m_functiong_client,
                m_functiong_country,
                m_functiong_procedure,
                m_functiong_document
        };

        /// <summary>
        /// 系统的表列表
        /// </summary>
        public static string m_table_project = "Project";
        public static string m_table_project_group = "ProjectGroup";
        public static string m_table_project_document = "ProjectDocument";
        public static string m_table_project_expenses = "ProjectExpenses";
        public static string m_table_project_class = "ProjectClass";
        public static string m_table_agent = "Agent";
        public static string m_table_client = "Client";
        public static string m_table_country = "Country";

        public static string[] m_sys_tables ={ 
                m_table_project,
                m_table_project_group,
                m_table_project_document,
                m_table_project_expenses,
                m_table_project_class,
                m_table_agent,
                m_table_client,
                m_table_country,
        };

        /// <summary>
        /// 用户组类别
        /// </summary>
        public static string m_str_group_type_administrator = "Administrator";
        public static string m_str_group_type_operator = "Operator";
        public static string m_str_group_type_normal = "Normal";

        public static string[] m_grouptypes ={ 
                m_str_group_type_administrator,
                m_str_group_type_operator,
                m_str_group_type_normal,
        };

        public static string m_str_role_management = "Management";
        public static string m_str_role_supervisor = "Supervisor";
        public static string m_str_role_user = "User";
        public static string m_str_role_engineer = "Engineer";

        public static string[] m_user_roles ={ 
                m_str_role_management,
                m_str_role_supervisor,
                m_str_role_user,
                m_str_role_engineer,
        };

        /// <summary>
        /// 系统seesion的参数
        /// </summary>
        public static string m_str_session_userid = "UserId";
        public static string m_str_session_username = "UserName";
        public static string m_str_session_loginname = "LoginName";
        public static string m_str_session_usergroupid = "OwnerGroupID";
        public static string m_str_session_usergroupname = "UserGroupName";
        public static string m_str_session_userrole = "UserRole";
        public static string m_str_session_usertype = "UserType";
        public static string m_str_session_useralertday = "AlertDay";
        public static string m_str_session_issuperuser = "SuperUser";



        //**********************************************//

        /// <summary>
        /// 判断当前用户是否是Administrator
        /// </summary>
        public static bool IsAdministratorUsertype()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_usertype] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_usertype].ToString().ToLower()
                    == m_str_group_type_administrator.ToLower())
            {
                return true;
            }
            return false;
        }


        /// <summary>
        /// 判断当前用户是否是Operator
        /// </summary>
        /// <returns></returns>
        public static bool IsOperatorUsertype()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_usertype] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_usertype].ToString().ToLower()
                    == m_str_group_type_operator.ToLower())
            {
                return true;
            }
            return false;
        }


        /// <summary>
        /// 判断当前用户是否是Normal
        /// </summary>
        /// <returns></returns>
        public static bool IsNormalUserType()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_usertype] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_usertype].ToString().ToLower()
                    == m_str_group_type_normal.ToLower())
            {
                return true;
            }
            return false;
        }


        /// <summary>
        /// 判断当前用户是否是Administrator or Normal
        /// </summary>
        /// <returns></returns>
        public static bool IsAdministratorOrNormalUserType()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_usertype] != null)
            {
                string userType = HttpContext.Current.Session[SysUtil.m_str_session_usertype].ToString().ToLower();
                if (userType == m_str_group_type_normal.ToLower() || userType == m_str_group_type_administrator.ToLower())
                {
                    return true;
                }
            }
            return false;
        }


        /// <summary>
        /// 判断当前用户是否是Administrator or Operator
        /// </summary>
        /// <returns></returns>
        public static bool IsAdministratorOrOperatorUserType()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_usertype] != null)
            {
                string userType = HttpContext.Current.Session[SysUtil.m_str_session_usertype].ToString().ToLower();
                if (userType == m_str_group_type_operator.ToLower() || userType == m_str_group_type_administrator.ToLower())
                {
                    return true;
                }
            }
            return false;
        }

        public static bool IsManagement()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_userrole] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower()
                    == m_str_role_management.ToLower())
            {
                return true;
            }
            return false;
        }

        public static bool IsSupervisor()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_userrole] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower()
                    == m_str_role_supervisor.ToLower())
            {
                return true;
            }
            return false;
        }

        public static bool IsUser()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_userrole] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower()
                    == m_str_role_user)
            {
                return true;
            }
            return false;
        }

        public static bool IsEngineer()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_userrole] != null
                && HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower()
                    == m_str_role_engineer.ToLower())
            {
                return true;
            }
            return false;
        }

        public static bool IsManagementSupervisor()
        {
            if (HttpContext.Current.Session[SysUtil.m_str_session_userrole] != null
                && (HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower() 
                == m_str_role_management.ToLower() 
                || HttpContext.Current.Session[SysUtil.m_str_session_userrole].ToString().ToLower() 
                == m_str_role_supervisor.ToLower()))
            {
                return true;
            }

            return false;
        }
    }
}
